package com.aaa.statistics.service.impl;


import com.aaa.entity.HisCareOrderItem;
import com.aaa.statistics.dao.SalesDao;
import com.aaa.statistics.service.SalesService;

import com.aaa.statistics.vo.HisCareOrderItemSaleVo;
import com.aaa.statistics.vo.HisCareOrderItemVo;
import com.aaa.statistics.vo.HisVO;
import com.aaa.vo.Result;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.List;
import java.util.Objects;

/**
 * @author ：晋升（js20020923@qq.com）
 * @date ：Created in 2023/3/29 9:49
 * @description：
 * @modified By：
 * @version:
 */
@Service
public class SalesServiceImpl extends ServiceImpl<SalesDao,HisCareOrderItem> implements SalesService {
    @Autowired
    private SalesDao salesDao;

    @Override
    public Result<IPage<HisCareOrderItem>> HisgetByPage(Integer currentPage, Integer pageSize, HisVO hisVO) {
        IPage<HisCareOrderItem> page=new Page<>(currentPage,pageSize);
        QueryWrapper<HisCareOrderItem> wrapper=new QueryWrapper<>();
        //默认条件查询
        wrapper.eq("item_type",0);
        wrapper.eq("status",3);
//        wrapper.eq("create_time",);
        //条件查询  前端传递数据到后端
        if (StringUtils.hasText(hisVO.getDrugName())){
            //字段名要跟数据库内保持一致
            wrapper.like("item_name",hisVO.getDrugName());
        }
        if (Objects.nonNull(hisVO.getDateRange())&&hisVO.getDateRange().length==2){
            wrapper.between("create_time",hisVO.getDateRange()[0],hisVO.getDateRange()[1]);
        }else {
            LocalDateTime now = LocalDateTime.now();
            String format = now.format(DateTimeFormatter.ofPattern("yyyy-MM-dd"));
            wrapper.like("create_time",format);//默认当前时间
        }
        IPage<HisCareOrderItem> page1 = salesDao.selectPage(page, wrapper);
        return new Result<>(2000,"查询药品销售",page1);
    }

    //    HisgetByPagestat
    @Override
    public Result<List<HisCareOrderItemSaleVo>> listStat(HisCareOrderItemVo hisCareOrderItemVo) {
        List<HisCareOrderItemSaleVo> hisCareOrderItemVos = salesDao.selectquery(hisCareOrderItemVo);
        return new Result<>(2000,"查询药品销售",hisCareOrderItemVos);
    }
}

